﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net;
using System.IO;
using System.Data;
using System.Xml;
using System.Xml.Serialization;
using System.Collections;
using System.Web.Script.Serialization;
using System.Web.Script.Services;


namespace BattleshipPortal.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            HttpWebRequest req;
            string strGet = "http://localhost:48361/IBattleship.asmx/getUserList";
            strGet = strGet + "";
            req = (HttpWebRequest)WebRequest.Create(strGet);
            HttpWebResponse response;
            response = (HttpWebResponse)req.GetResponse();
            Stream stream = response.GetResponseStream();
            XmlTextReader reader = new XmlTextReader(stream);
            reader.MoveToContent();

            ArrayList list = (ArrayList)this.DeserializeFromXml(reader.ReadString(), typeof(ArrayList));
            reader.ReadInnerXml();

            ViewData["Message"] = "Welcome to Battleship Portal Website ";// +list.ToArray().ToString();
            reader.Close();



            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        protected object DeserializeFromXml(string s, Type t)
        {
            XmlSerializer serializer = new XmlSerializer(t);
            object obj2 = null;
            XmlTextReader xmlReader = new XmlTextReader(s, XmlNodeType.Element, null);
            obj2 = serializer.Deserialize(xmlReader);
            xmlReader.Close();
            return obj2;
        }
    }
}
